home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / gpr.trm < prev    next >
Text File  |  1993-09-15  |  12KB  |  384 lines

  1. /*
  2.  * $Id: gpr.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - gpr.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   APOLLO's GPR windowing system
  26.  *
  27.  * AUTHORS
  28.  *  Michael Aramini
  29.  *  Roque D Oliveira , oliveria@caen.engin.umich.edu
  30.  * 
  31.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  32.  * 
  33.  */
  34. #include <apollo/base.h>
  35. #include <apollo/error.h>
  36. #include <apollo/gpr.h>
  37. #include <apollo/pad.h>
  38. /* landscape window */
  39. /*
  40. #define GPR_XMAX 720
  41. #define GPR_YMAX 450
  42. */
  43. /* portrait window */
  44. #define GPR_XMAX 585
  45. #define GPR_YMAX 735
  46.  
  47. #define GPR_XLAST (GPR_XMAX - 1)
  48. #define GPR_YLAST (GPR_YMAX - 1)
  49.  
  50. #define GPR_VCHAR 19
  51. #define GPR_HCHAR 10
  52. #define GPR_VTIC (GPR_YMAX/80)
  53. #define GPR_HTIC (GPR_XMAX/80)
  54.  
  55. gpr_$direction_t  gpr_path=gpr_$right;
  56. int               gpr_ang=0;            /* text angle, 0=horizontal, 1=vertical */
  57. enum JUSTIFY      gpr_justify=LEFT;     /* text is flush left */
  58.  
  59. static status_$t  status;
  60. unsigned int      Debug    = 0;         /* set it to 1 when debugging program */
  61.  
  62.  
  63. static void check(messagex)
  64. char *messagex;
  65. {
  66.   if (status.all = status_$ok)
  67.   {
  68.     error_$print(status);
  69.     printf("Error occurred while %s.\n", messagex);
  70.   }
  71. }
  72.  
  73. /* return whether stdout is a DM pad . Called by term.c */
  74. gpr_isa_pad()
  75. {
  76.     pad_$isa(1, &status);
  77.     return (status.all == status_$ok);
  78. }
  79.  
  80.  
  81. GPR_init()
  82. {
  83.   gpr_$offset_t dm_bitmap_size;
  84.   gpr_$bitmap_desc_t dm_bitmap_desc;
  85.   pad_$window_desc_t window;
  86.   short font_id;
  87.   stream_$id_t stream_id;
  88.   static gpr_$rgb_plane_t  hi_plane;
  89.   static gpr_$disp_char_t  display_characteristics;
  90.   static float             screen_size_r_width,screen_size_r_height ;
  91.   static short int         disp_len = sizeof(gpr_$disp_char_t);
  92.   static short int         disp_len_returned;
  93.  
  94.  
  95.   /* open a pad to do graphics in */
  96.   window.top    = 0;
  97.   window.left   = 0;
  98.   window.width  = GPR_XMAX + 10; /* 10 accounts for width of window border */
  99.   window.height = GPR_YMAX + 35; /* 35 accounts for height of window border */
  100.   pad_$create_window("",(short)0,pad_$transcript,(short)1,window,&stream_id,&status);
  101.   check("pad_$create_window");
  102.  
  103. /*  pad_$set_full_window(stream_id,(short) 1,&window, &status); */
  104. /*  pad_$set_border (stream_id,(short) 1, true, &status); */
  105.   pad_$set_scale (stream_id,(short) 1,(short) 1, &status);
  106.   pad_$set_auto_close(stream_id, (short) 1, true, &status );
  107.  
  108.   gpr_$inq_disp_characteristics(gpr_$direct,stream_id,disp_len,&display_characteristics,&disp_len_returned,&status);
  109.   check("in gpr_$inq_display_characteristics");
  110.   screen_size_r_width    = (float) display_characteristics.x_window_size;    /*x_window_size in pixels */
  111.   screen_size_r_height   = (float) display_characteristics.y_window_size;    /*y_window_size in pixels */
  112.   hi_plane  = display_characteristics.n_planes - 1;  
  113.   if(Debug) printf("width=%f height=%f \n",screen_size_r_width,screen_size_r_height);
  114.  
  115.   dm_bitmap_size.x_size = 1280;
  116.   dm_bitmap_size.y_size = 1024;
  117.   gpr_$init(gpr_$direct,stream_id,dm_bitmap_size,hi_plane,&dm_bitmap_desc,&status); 
  118.   check("in gpr_$init");
  119. /*
  120.   gpr_$set_obscured_opt(gpr_$pop_if_obs, &status); 
  121.   check("in gpr_$set_obscured_opt");
  122. */
  123.   gpr_$set_auto_refresh(true, &status); 
  124.   check("in gpr_$set_auto_refresh");
  125.  
  126.   /* load a font and make it current */
  127.   gpr_$load_font_file("f7x13", 5, &font_id, &status);
  128.   check("in gpr_$load_font_file");
  129.   gpr_$set_text_font(font_id, &status);
  130.   check("in gpr_$set_text_font");
  131.  
  132.   /* set up color values */
  133.   gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  134.   check("in gpr_set_draw_value");
  135.   gpr_$set_text_background_value((gpr_$pixel_value_t)(-1), &status); /* trans */
  136.   check("in gpr_$set_text_background_value");
  137.   gpr_$set_text_value((gpr_$pixel_value_t)7, &status);  /* white */
  138.   check("in gpr_$set_text_value");
  139. }
  140.  
  141.  
  142. GPR_graphics()
  143. {
  144.   gpr_$coordinate_t locx,locy,marker_size;
  145.  
  146.   (void) gpr_$acquire_display(&status);
  147.   check("in gpr_$acquire display");
  148.   gpr_$clear((gpr_$pixel_value_t)0, &status);  /* black */
  149.   check("in gpr_$clear");
  150.  
  151.   if(Debug) 
  152.    {
  153.     marker_size = (short) 10;  
  154.  
  155.     locx = (short) 5;
  156.     locy = (short) 5;
  157.     gpr_$set_draw_value((gpr_$pixel_value_t)2, &status);  /* white */
  158.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  159.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  160.     gpr_$move( locx, (locy + marker_size/2),&status);
  161.     gpr_$line( locx, (locy - marker_size/2),&status);
  162.     
  163.     locx = (short) (GPR_XMAX -1 - 5);
  164.     locy = (short) 5;
  165.     gpr_$set_draw_value((gpr_$pixel_value_t)3, &status);  /* white */
  166.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  167.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  168.     gpr_$move( locx, (locy + marker_size/2),&status);
  169.     gpr_$line( locx, (locy - marker_size/2),&status);
  170.     
  171.     locx = (short) 5;
  172.     locy = (short) (GPR_YMAX -1 - 5);
  173.     gpr_$set_draw_value((gpr_$pixel_value_t)4, &status);  /* white */
  174.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  175.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  176.     gpr_$move( locx, (locy + marker_size/2),&status);
  177.     gpr_$line( locx, (locy - marker_size/2),&status);
  178.     
  179.     locx = (short) (GPR_XMAX -1 - 5);
  180.     locy = (short) (GPR_YMAX -1 - 5);
  181.     gpr_$set_draw_value((gpr_$pixel_value_t)5, &status);  /* white */
  182.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  183.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  184.     gpr_$move( locx, (locy + marker_size/2),&status);
  185.     gpr_$line( locx, (locy - marker_size/2),&status);
  186.     
  187.     gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  188.     check("in gpr_$set_draw_value");
  189.    } /* end if(Debug) */
  190.  
  191. }
  192.  
  193.  
  194. GPR_text()
  195. {
  196.   gpr_$release_display(&status);
  197.   check("gpr_$release_display");
  198. }
  199.  
  200.  
  201. GPRold_linetype(linetype)
  202. int linetype;
  203. {
  204.   static gpr_$line_pattern_t patterns[2+5] = {
  205.       { 0xFFFF },   /* solid              1111111111111111 */
  206.       { 0x3FFF },   /* very long dashed   0011111111111111 */
  207.       { 0xFFFF },   /* solid              1111111111111111 */
  208.       { 0x5555 },   /* dotted             0101010101010101 */
  209.       { 0x3333 },   /* short dashed       0011001100110011 */
  210.       { 0xB5AD },   /* dot short-dashed   1011010110101101 */
  211.       { 0x3FFF }    /* very long dashed   0011111111111111 */
  212.                                              };
  213.   if (linetype >= 5) linetype %= 5;
  214.   gpr_$set_line_pattern((short)1, patterns[linetype+2], (short)16, &status);
  215.   check("in gpr_$set_line_pattern");
  216. }
  217.  
  218. GPR_linetype(linetype)
  219. int linetype;
  220. {
  221.   static gpr_$line_pattern_t patterns[2+7] = {
  222.       { 0xFFFF },   /* solid              1111111111111111 */
  223.       { 0x1111 },   /* long-spaced dotted 0001000100010001 */
  224.       { 0xFFFF },   /* solid              1111111111111111 */
  225.       { 0x5555 },   /* dotted             0101010101010101 */
  226.       { 0x3333 },   /* short  dashed      0011001100110011 */
  227.       { 0x7777 },   /* medium dashed      0111011101110111 */
  228.       { 0x3F3F },   /* long   dashed      0011111100111111 */
  229.       { 0x0F0F },   /* long-spaced dashed 0000111100001111 */
  230.       { 0x5F5F }    /* dot dashed         0101111101011111 */
  231.                                              };
  232.   if (linetype >= 7) linetype %= 7;
  233.   gpr_$set_line_pattern((short)1, patterns[linetype+2], (short)16, &status);
  234.   check("in gpr_$set_line_pattern");
  235.  
  236. /*
  237.   gpr_$set_draw_value((gpr_$pixel_value_t)(linetype + 1), &status);
  238.   check("in gpr_$set_draw_value");
  239. */
  240. }
  241.  
  242.  
  243. GPR_move(x, y)
  244. unsigned int x, y;
  245. {
  246.   gpr_$move((short)x, (short)(GPR_YMAX -1 - y), &status);
  247.   check("in gpr_$move");
  248. }
  249.  
  250.  
  251. GPR_vector(x, y)
  252. unsigned int x, y;
  253. {
  254.   gpr_$line((short)x, (short)(GPR_YMAX -1 - y), &status);
  255.   check("in gpr_$line");
  256. }
  257.  
  258.  
  259. GPR_put_text(x,y,str)
  260. unsigned int x,y;        /* reference point of string */
  261. char str[];              /* the text */
  262. {
  263.   gpr_$coordinate_t xgpr,ygpr;
  264.   gpr_$offset_t     str_size_in_pixels;
  265.   short int         str_len;     
  266.  
  267.   gpr_$coordinate_t locx,locy,marker_size;
  268.  
  269.   if(Debug) 
  270.    {
  271.     locx = (short) x;
  272.     locy = (short) (GPR_YMAX -1 - y);
  273.     marker_size = (short) 20;  
  274.     gpr_$set_draw_value((gpr_$pixel_value_t)1, &status);  /* white */
  275.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  276.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  277.     gpr_$move( locx, (locy + marker_size/2),&status);
  278.     gpr_$line( locx, (locy - marker_size/2),&status);
  279.     gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  280.    }
  281.  
  282.   xgpr = (short) x;
  283.   ygpr = (short) (GPR_YMAX -1 - y); 
  284.   gpr_$set_text_path(gpr_path, &status); 
  285.   check("gpr_$set_text_path");
  286.  
  287.   str_len = (short) strlen(str);
  288.   gpr_$inq_text_extent(str,str_len,&str_size_in_pixels,&status); /* Calculate how much space (in pixels) the string requires */    
  289.   check("in gpr_$inq_text_extent");
  290.  
  291.   switch (gpr_justify) 
  292.    {
  293.     case LEFT :
  294.         {
  295.          switch (gpr_path) 
  296.           {
  297.            case gpr_$up :           /* vertical */
  298.                {
  299.                 if(Debug) printf("LEFT and up , str=%s\n",str);
  300.                 break;
  301.                }
  302.            case gpr_$right :        /* horizontal */
  303.                {
  304.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  305.                 if(Debug) printf("LEFT and right, str=%s \n",str);
  306.                 break;
  307.                }
  308.           }
  309.          break;
  310.         }
  311.  
  312.     case CENTRE :
  313.         {  
  314.          switch (gpr_path) 
  315.           {
  316.            case gpr_$up :           /* vertical */
  317.                {
  318.                 xgpr = xgpr + str_size_in_pixels.x_size/2;
  319.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  320.                 if(Debug) printf("CENTRE and up, str=%s \n",str);
  321.                 break;
  322.                }
  323.            case gpr_$right :        /* horizontal */
  324.                {
  325.                 xgpr = xgpr - str_size_in_pixels.x_size/2;
  326.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  327.                 if(Debug) printf("CENTRE and right, str=%s \n",str);
  328.                 break;
  329.                }
  330.           }
  331.          break;
  332.         }
  333.     case RIGHT :
  334.         {
  335.          switch (gpr_path) 
  336.           {
  337.            case gpr_$up :           /* vertical */
  338.                {
  339.                 ygpr = ygpr + str_size_in_pixels.y_size;
  340.                 if(Debug) printf("RIGHT and up, str=%s \n",str);
  341.                 break;
  342.                }
  343.            case gpr_$right :        /* horizontal */
  344.                {
  345.                 xgpr = xgpr - str_size_in_pixels.x_size;
  346.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  347.                 if(Debug) printf("RIGHT and right, str=%s \n",str);
  348.                 break;
  349.                }
  350.           }
  351.          break;
  352.         }
  353.    }
  354.  
  355.   gpr_$move(xgpr,ygpr,&status);
  356.   check("in gpr_$move");
  357.   gpr_$text(str, str_len, &status);
  358.   check("in gpr_$text");
  359. }
  360.  
  361. int GPR_text_angle(ang)
  362. int ang;
  363. {   
  364.     if (gpr_ang != ang)
  365.       {
  366.         gpr_ang  = ang;
  367.         gpr_path = (gpr_ang == 1 ? gpr_$up : gpr_$right);
  368.       }
  369.     return (TRUE);
  370. }
  371.  
  372. int GPR_justify_text(mode)
  373. enum JUSTIFY mode;
  374. {
  375.     gpr_justify = mode;
  376.     return (TRUE);
  377. }
  378.  
  379. GPR_reset()
  380. {
  381.   gpr_$terminate(false, &status);
  382.   check("in gpr_$terminate");
  383. }
  384.